package com.zhang.作业Test;

import com.zhang.作业.Rectangle;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

public class RectangleTest2 {
    public static void main(String[] args) {
        Rectangle r1=new Rectangle();
        Rectangle r2=new Rectangle();
        Rectangle r3=new Rectangle();
        Rectangle r4=new Rectangle();
        Rectangle r5=new Rectangle();
        Rectangle[] rectangles= {r1,r2,r3,r4,r5};
        Random random=new Random();
        for (Rectangle r : rectangles) {
            r.setChang(random.nextDouble()*9+1);
            r.setKuan(random.nextDouble()*9+1);
        }
        //显示遍历
        for (Rectangle rectangle : rectangles) {
            rectangle.getInfo();
        }
//        Arrays.sort(rectangles, new Comparator<Rectangle>() {
//            @Override
//            public int compare(Rectangle o1, Rectangle o2) {
//                return  (int) (o1.getArea()-o2.getArea());
//            }
//        });
        for (int i = 0; i < rectangles.length; i++) {
            int min=i;
            for (int i1 = i+1; i1 < rectangles.length; i1++) {
                if (rectangles[i1].getArea()<rectangles[min].getArea()){
                    min=i1;
                }
            }
            Rectangle tamp=rectangles[i];
            rectangles[i]=rectangles[min];
            rectangles[min]=tamp;
        }
        System.out.println("=============排序后==============");
        for (Rectangle rectangle : rectangles) {
            rectangle.getInfo();
        }

    }
}
